﻿using System;
using Glue;
using Glue.Internals.PrintTool;
using Xunit;

namespace GlueTests.PrintToolTests
{
    public class When_adjusting_columnsize
    {
        private readonly PrintTool<DomainPerson, GuiPerson> printtool;
        private Mapping<DomainPerson, GuiPerson> mapping;

        public class DomainPerson
        {
            public String AnExtremelyLongPropertyName { get; set; }
            public int ShrtProp { get; set; }
        }
        public class GuiPerson
        {
            public String APropertyOfLength19 { get; set; }
            public int ShrtProp { get; set; }
        }

        public When_adjusting_columnsize()
        {

            mapping = new Mapping<DomainPerson, GuiPerson>();
            printtool = new PrintTool<DomainPerson, GuiPerson>(mapping);
        }

        [Fact]
        public void Should_set_typenames_length_as_initial_size()
        {
            var report = printtool.GetReport();
            Assert.Equal("DomainPerson".Length,report.LeftColumnSize);
            Assert.Equal("GuiPerson".Length,report.RightColumnSize);
        }

        [Fact]
        public void Should_set_propertynames_length_as_new_length_if_longer_then_existing()
        {
            mapping.Relate(x=>x.AnExtremelyLongPropertyName,y=>y.APropertyOfLength19);
            var report = printtool.GetReport();
            Assert.Equal("AnExtremelyLongPropertyName".Length, report.LeftColumnSize);
            Assert.Equal("APropertyOfLength19".Length, report.RightColumnSize);
        }

        [Fact]
        public void Should_not_set_new_length_of_propertynames_length_is_shorter_than_existing()
        {
            mapping.Relate(x => x.ShrtProp, y => y.ShrtProp);
            var report = printtool.GetReport();
            Assert.Equal("DomainPerson".Length, report.LeftColumnSize);
            Assert.Equal("GuiPerson".Length, report.RightColumnSize);
        }
    }
}
